//导入request.js请求工具
import request from '@/utils/request'
let codekey = ''
//提供调用用户注册的接口
export const userRegisterService = (registerData) => {
  //借助UrlSearchParams对象封装请求参数
  const params = new URLSearchParams()
  for (let key in registerData) {
    params.append(key, registerData[key])
  }
  return request.post('/admin/register', params)
}

//提供调用用户登录的接口
export const userLoginService = (loginData) => {
  //借助UrlSearchParams对象封装请求参数
  const params = new URLSearchParams()
  for (let key in loginData) {
    params.append(key, loginData[key])
  }
  params.append('key', codekey)
  return request.post('/common/login', params)
}
//获取验证码
export const captchaService = () => {
  codekey = Math.random()
  return request.post('captcha?key=' + codekey)
}
//退出登录
export const userLogoutService = () => {
  return request.post('/common/logout')
}

//获取用户信息
export const getUserInfoService = () => {
  return request.get('/common/userInfo')
}
export const updateUserInfoService = (userInfoData) => {
  return request.put('/common/update', userInfoData)
}

export const userPwdUpdateService = (data) => {
  return request.put('/common/password', data)
}

export const uploadFileService = (formData) => {
  return request.post('/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};